#include<iostream>
using namespace std;
class MyTime
{
private:
    int hour;
    int minute;
    int second;
public:
    MyTime()
    {
        hour = 0;
        minute = 0;
        second = 0;
    }
    MyTime(int _hour, int _minute, int _second)
    {
        hour = _hour;
        minute = _minute;
        second = _second;
    }
    void SetTime(int _hour, int _minute, int _second)
    {
        hour = _hour;
        minute = _minute;
        second = _second;
    }
    void addTime(int h,int m,int s)
    {
        hour += h;
        minute += m;
        second += s;
        if(second>=60)
        {
            second = second -60;
            minute = minute + 1;
        }
        if(minute>=60)
        {
            minute = minute - 60;
            hour = hour + 1;
        }
        if(hour>=24)
        {
            hour = hour -24;
        }
    }
    void reduceTime(int _h,int _m,int _s)
    {
        if(second<_s)
        {
            second += 60;
            minute --;
        }
        if(minute<_m)
        {
            minute += 60;
            hour --;
        }
        if(hour<_h)
        {
            hour = hour + 24;
        }
        hour -= _h;
        minute -= _m;
        second -= _s;
    }
    void print_12()
    {
        int tempHour;
        hour>=12?tempHour=hour-12:tempHour=hour;
        if(tempHour<10){
            cout<<'0';
        }
        cout<<tempHour<<':';
        if(minute<10){
            cout<<'0';
        }
        cout<<minute<<':';
        if(second<10){
            cout<<'0';
        }
        cout<<second;
        if(hour>12||((hour==12)&&((minute>0)||(second>0)))){
            cout<<" "<<"PM"<<endl;
        }else{
            cout<<" "<<"AM"<<endl;
        }
    }
    void print_24()
    {
        if(hour<10){
            cout<<'0';
        }
        cout<<hour<<':';
        if(minute<10){
            cout<<'0';
        }
        cout<<minute<<':';
        if(second<10){
            cout<<'0';
        }
        cout<<second<<endl;
    }
};


int main()
{
    MyTime t1;
    MyTime t2(8,10,30);
    t1.print_12();
    t1.print_24();
    t2.print_12();
    t2.print_24();
    int h1,m1,s1,h2,m2,s2;
    cin>>h1>>m1>>s1;
    t1.SetTime(h1, m1, s1);
    cin>>h2>>m2>>s2;
    t1.addTime(h2,m2,s2);
    t2.reduceTime(h2, m2, s2);
    t1.print_12();
    t1.print_24();
    t2.print_12();
    t2.print_24();
    return 0;
}